package org.smart4j.framework.aspect;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.annotation.Aspect;
import org.smart4j.framework.annotation.Controller;
import org.smart4j.framework.proxy.AspectProxy;
import org.smart4j.framework.proxy.ProxyChain;

import java.lang.reflect.Method;

/**
 *
 * 拦截 Controller 所有方法
 *
 * @author: Mr.Zhou
 * @create: 2018-10-25 16:18
 **/
@Aspect(Controller.class)
public class ControllerAspect extends AspectProxy {

    private static final Logger LOGGER= LoggerFactory.getLogger(ControllerAspect.class);

    private long begin;

    @Override
    public Object dePorxy(ProxyChain proxyChain) throws Throwable {
        return super.dePorxy(proxyChain);
    }


    @Override
    public void before(Class<?> cls, Method method, Object[] params) throws Throwable {
        LOGGER.debug("---------- begin ----------");
        LOGGER.debug(String.format("class:%s",cls.getName()));
        LOGGER.debug(String.format("method:%s",method.getName()));
//        super.before(cls, method, params);
        begin=System.currentTimeMillis();
    }

    @Override
    public void after(Class<?> cls, Method method, Object[] params, Object result) throws Throwable {
        LOGGER.debug(String.format("title:%dms",System.currentTimeMillis()-begin));
        LOGGER.debug("---------- end ----------");
//        super.after(cls, method, params, result);
    }

}
